﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;
namespace ZF.WS.UserControls.Index
{
    public partial class News : System.Web.UI.UserControl
    {


         
 
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
            
                string[] types = DictionaryConfig.INewType.Select(p=>p.Key).ToArray();
                  Dictionary<object, List<Model.I_News>> dicType =null;
                var cacheKey = "_Index_News";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    dicType = obj as Dictionary<object, List<Model.I_News>>;
                }
                else
                {
                    dicType = new Dictionary<object, List<Model.I_News>>();
                    foreach (var type in types)
                    {
                        var list = dc.I_News.Where(p => p.Type == type&&p.IsV)
                            .OrderBy(p=>p.Focus)
                            .OrderByDescending(p => p.NewsId).Take(13)
                            .ToList();
      
                        dicType[type] = list;
                    }

                    SiteInfo.Instance.SetPageCache(cacheKey, dicType);
                }
                this.lvTitle.DataSource = dicType.Where(p => !(new string[]{"特别关注","本站动态"}).Contains(p.Key)).ToList();
                this.lvTitle.DataBind();
                
                 

                var gzList = dicType["特别关注"];//特别关注
        
                //NewPlay = gzList.Select(p =>
                //    {
                //        return string.Format("<a image='/photo/news/{0}' url='/news/index.aspx?id={1}' info='{2}'/>"
                //            , p.Photo.Replace(";", ""), p.NewsId, p.Title).Replace("\"","’");;
                //    }).ConstituteString("");
                this.lvNews.DataSource = dicType.Where(p => !(new string[] { "特别关注", "本站动态" }).Contains(p.Key)).ToList();
                this.lvNews.DataBind();
                this.lvSiteNew.DataSource = dicType["本站动态"].Take(4);
                this.lvSiteNew.DataBind();
                 
            }
        }
    }
}